package com.example.go;

import com.example.go.book.BookService;
import com.example.go.user.UserService;
import com.example.jk.core.Context;
import com.example.jk.core.Koa;
import com.example.jk.middlewares.JsonMiddleware;
import com.example.jk.middlewares.LoggingMiddleware;
import com.example.jk.middlewares.RouteMiddleware;
import com.example.jk.middlewares.StaticResourceMiddleware;
import com.example.jk.middlewares.UndertowServerPlugin;

public class App {

	public static void main(String[] args) {
		Context context = new Context();
		Koa koa = new Koa();
		UserService userService = new UserService();
		BookService bookService = new BookService();

		RouteMiddleware route = new RouteMiddleware();

		route.register("/users", "GET", userService::getUser);
		route.register("/users", "POST", userService::addUser);
		route.register("/books", "GET", bookService::getBook);
		route.register("/books", "POST", bookService::addBook);
		koa.registerMiddleware(route);

		koa.registerMiddleware(new LoggingMiddleware());
		koa.registerMiddleware(new StaticResourceMiddleware());
		
		koa.registerMiddleware(new JsonMiddleware()); // 注册 JSON 中间件
		koa.registerMiddleware(new UndertowServerPlugin(koa));
//		koa.handleRequest(context);
	}
}